using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Text.RegularExpressions;

namespace JQuery
{
    public class SortableExtender : UIExtender
    {
        public SortableExtender()
        {
            Revert = "invalid";
            ChangeMetadata("Stack", new JQueryElementAttribute(null, "stack", false, @"^\{ group: '" + string.Format(JQueryElementAttribute.VariableSelectorRegexPattern, "false") + @"'(, min:[0-9]+)? \}$"));
        }

        [JQueryElement("connectWith", true)]
        public string ConnectSelector
        {
            get { return GetPropertyValue<string>("ConnectSelector", null); }
            set { SetPropertyValue("ConnectSelector", value); }
        }

        [JQueryElement("dropOnEmpty")]
        public bool? DropOnEmpty
        {
            get { return GetPropertyValue<bool>("DropOnEmpty", null); }
            set { SetPropertyValue("DropOnEmpty", value); }
        }

        [JQueryElement("forceHelperSize")]
        public bool? ForceHelperSize
        {
            get { return GetPropertyValue<bool>("ForceHelperSize", null); }
            set { SetPropertyValue("ForceHelperSize", value); }
        }

        [JQueryElement("forcePlaceholderSize")]
        public bool? ForcePlaceHolderSize
        {
            get { return GetPropertyValue<bool>("ForcePlaceHolderSize", null); }
            set { SetPropertyValue("ForcePlaceHolderSize", value); }
        }


        [JQueryElement("items", true)]
        public string ItemSelector
        {
            get { return GetPropertyValue<string>("ItemSelector", null); }
            set { SetPropertyValue("ItemSelector", value); }
        }

        [JQueryElement("handle", true)]
        public string HandleSelector
        {
            get { return GetPropertyValue<string>("HandleSelector", null); }
            set { SetPropertyValue("HandleSelector", value); }
        }


        [JQueryElement("placeholder", false, SerializeAs = SerializeAs.String)]
        public string DropPlaceHolderCssClass
        {
            get { return GetPropertyValue<string>("DropPlaceHolderCssClass", null); }
            set
            {
                SetPropertyValue("DropPlaceHolderCssClass", value);
                SetPropertyValue("forcePlaceHolderSize", !string.IsNullOrEmpty(value));
            }
        }

        [JQueryEvent("start")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnStart
        {
            get { return GetPropertyValue<string>("OnStart", null); }
            set { SetPropertyValue("OnStart", value); }
        }

        [JQueryEvent("sort")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnSort
        {
            get { return GetPropertyValue<string>("OnSort", null); }
            set { SetPropertyValue("OnSort", value); }
        }

        [JQueryEvent("change")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnChange
        {
            get { return GetPropertyValue<string>("OnChange", null); }
            set { SetPropertyValue("OnChange", value); }
        }

        [JQueryEvent("beforeStop")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnBeforeStop
        {
            get { return GetPropertyValue<string>("OnBeforeStop", null); }
            set { SetPropertyValue("OnBeforeStop", value); }
        }

        [JQueryEvent("stop")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnStop
        {
            get { return GetPropertyValue<string>("OnStop", null); }
            set { SetPropertyValue("OnStop", value); }
        }

        [JQueryEvent("update")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnUpdate
        {
            get { return GetPropertyValue<string>("OnUpdate", null); }
            set { SetPropertyValue("OnUpdate", value); }
        }

        [JQueryEvent("receive")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnReceive
        {
            get { return GetPropertyValue<string>("OnReceive", null); }
            set { SetPropertyValue("OnReceive", value); }
        }

        [JQueryEvent("remove")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnRemove
        {
            get { return GetPropertyValue<string>("OnRemove", null); }
            set { SetPropertyValue("OnRemove", value); }
        }

        [JQueryEvent("over")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnOver
        {
            get { return GetPropertyValue<string>("OnOver", null); }
            set { SetPropertyValue("OnOver", value); }
        }

        [JQueryEvent("out")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnOut
        {
            get { return GetPropertyValue<string>("OnOut", null); }
            set { SetPropertyValue("OnOut", value); }
        }

        [JQueryEvent("activate")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnActivate
        {
            get { return GetPropertyValue<string>("OnActivate", null); }
            set { SetPropertyValue("OnActivate", value); }
        }

        [JQueryEvent("deactivate")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public string OnDeActivate
        {
            get { return GetPropertyValue<string>("OnDeActivate", null); }
            set { SetPropertyValue("OnDeActivate", value); }
        }

        protected override string jQueryFunction
        {
            get { return "sortable"; }
        }
    }
}
